package com.example.mycomposelearing.scroll

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.mycomposelearing.scroll.ui.theme.MyComposeLearingTheme

class ScrollMainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyComposeLearingTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("Android")
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    val  scrollableState=rememberScrollState()
    Column(
        modifier = Modifier
            .fillMaxHeight()
            .verticalScroll(scrollableState)
    ) {
//        Column(modifier = Modifier.fillMaxHeight()) {
            Text(
                modifier = Modifier
                    .background(Color(0xFFCF2020))
                    .height(100.dp),
                text = "第一个的---Item box"
            )
            Text(
                modifier = Modifier
                    .background(Color(0xFF2098CF))
                    .height(100.dp),
                text = "第2个的---Item box"
            )
            LazyColumn(modifier = Modifier.height(100.dp).background(Color(0xFF1E39AF))) {
                items(20) {
                    Text(text = "第一个的---Item $it")
                    Text(text = "第一个的---Item $it")
                }
            }

    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    MyComposeLearingTheme {
        Greeting("Android")
    }
}